package edu.chl.tda367.mynotes.util;

import java.io.File;
import java.util.*;
import java.util.Scanner;

/*
 * Class that is used to set file extension filters for the JFileChooser.
 */

public class ExtensionFilter extends javax.swing.filechooser.FileFilter {

	private List<String> extension = new ArrayList<String>();
	private String description = "";

	public ExtensionFilter(String suffix){
		Scanner sc = new Scanner(suffix);
		while(sc.hasNext()){
			String s = sc.next();
			extension.add(s);
			description += "*" + s + " ";
		}
	}


	@Override
	public boolean accept(File f) {
		if (f.isDirectory()){
			return true;
		}
		for(String s: extension){
			if(f.getName().endsWith(s)){
				return true;
			}
		}
		return false;
	}

	@Override
	public String getDescription() {
		return description;
	}
}
